package com.itboye.textileexpes.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.itboye.textileexpes.beans.OfferLineOrderBeans;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.util.MyToast;
import com.itboye.textileexpres.util.TimeFormat;

/**
 * Created by GuoEH on 2016/11/9.
 */

public class MyOfflineOrderAdapter extends BaseExpandableListAdapter {

	Context context;
	OfferLineOrderBeans beans;

	public MyOfflineOrderAdapter(Context context, OfferLineOrderBeans beans) {
		this.context = context;
		this.beans = beans;
	}

	@Override
	public int getGroupCount() {
		return Integer.valueOf(beans.getCount());
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		return beans.getList().get(groupPosition).getProcessed_order_items()
				.get(0).getItems().size();
	}

	@Override
	public Object getGroup(int groupPosition) {
		return beans.getList().get(groupPosition);
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		return beans.getList().get(groupPosition).getProcessed_order_items()
				.get(0).getItems().get(childPosition);
	}

	@Override
	public long getGroupId(int groupPosition) {
		return beans.getList().get(groupPosition).getId();
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		
		return beans.getList().get(groupPosition).getProcessed_order_items()
				.get(0).getItems().get(childPosition).getId();
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		View view = LayoutInflater.from(context).inflate(R.layout.list_item,
				null);
		TextView tv = (TextView) view.findViewById(R.id.publish_author_tv);
		TextView Chandi = (TextView) view.findViewById(R.id.area_tv);
		int len = beans.getList().get(groupPosition).getProcessed_order_items()
				.size();
		for (int i = 0; i < len; i++) {
			tv.setText("发布人:"+beans.getList().get(groupPosition)
					.getProcessed_order_items().get(i).getPlace_origin()
					+ "");
			Chandi.setText("产地:"+beans.getList().get(groupPosition)
					.getProcessed_order_items().get(i).getContact_name()
					+ "");
		}

		// Chandi.setText(TimeFormat.DateFormat(beans.getList().get(groupPosition).getPlace_origin()+""));
		return view;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		View view = LayoutInflater.from(context)
				.inflate(R.layout.layout2, null);
		TextView name = (TextView) view.findViewById(R.id.name);
		TextView title = (TextView) view.findViewById(R.id.title);
		TextView time = (TextView) view.findViewById(R.id.time);
		name.setText(beans.getList().get(groupPosition)
				.getProcessed_order_items().get(0).getItems()
				.get(childPosition).getName()
				+ "");
		title.setText(beans.getList().get(groupPosition)
				.getProcessed_order_items().get(0).getItems()
				.get(childPosition).getSecondary()
				+ "");
		time.setText(beans.getList().get(groupPosition)
				.getProcessed_order_items().get(0).getItems()
				.get(childPosition).getContact_name()
				+ "");

		return view;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		return true;
	}
}
